﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;
using FineUIPro;

namespace CanDoo.Oil.WebApp.buyInStoreDetail
{
    public partial class Default : ListPageBase<IInStoreDetailContract, InStoreDetail>
    {


        public IInStoreContract InStoreContract { get; set; }
        public IProductContract ProductContract { get; set; }

        #region 方法
        protected override void InitGrid()
        {
            Selector = p => new
            {
                p.InStore,
                p.InStoreId,
                p.Product,
                p.ProductId,
                p.Price,
                p.Num,
                p.Money,
                p.AlreadyNum,
                p.AlreadyMoney,
                p.Coefficient,
                p.Remark,
                p.Id,
                p.Name
            };
            base.InitGrid();
        }

        protected override void Search()
        {
            var key = SearchKey.GetValue();
            var instoreId = SearchInStore.GetValue().ToLong();
            var productId = SearchProduct.GetValue().ToLong();
            if(string.IsNullOrEmpty(key) == false)
            {
                Filter = Filter.And(p => p.Name.Contains(key));
            }
            if (instoreId >  0L)
                Filter = Filter.And(p => p.InStoreId == instoreId);
            if (productId >  0L)
                Filter = Filter.And(p => p.ProductId == productId);
        }
        #endregion

        #region 事件
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //FineUIListHelper.BindDDL<InStore>("采购入库单",InStoreContract.GetResolvedTree(), 0L, SearchInStore);
                //FineUIListHelper.BindDDL(InStoreContract.EntityName, this.InStoreContract.GetSelectList(), 0L, SearchInStore);
                //FineUIListHelper.BindDDL<Product>("产品",ProductContract.GetResolvedTree(), 0L, SearchProduct);
                //FineUIListHelper.BindDDL(ProductContract.EntityName, this.ProductContract.GetSelectList(), 0L, SearchProduct);
                InitGrid();
            }
        }
        #endregion

        #endregion 事件

    }
}
